package;


import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.util.FlxColor;
import flixel.addons.text.FlxTypeText;

/**
 * A FlxState which can be used for the game's menu.
 */
class UltimoState extends PreguntaState
{
	
	private var time1:Float;
	private var time2:Float;
	private var time3:Float;
	private var time4:Float;
	/**
	 * Function that is called up when to state is created to set it up. 
	 */
	
	override public function create():Void
	{
		super.create();
		time1 = 31;
		time2 = 31;
		time3 = 31;
		time4 = 31;
		estado = "esperando2";
	}
	
	override public function update():Void
	{
		super.update();
		switch(estado)
		{
			case "esperando2":
				_reloj -= FlxG.elapsed;
				_relojTexto.text = Std.string(Std.int(_reloj));
				if (player1.getInput() == -1)
					time1 -=FlxG.elapsed;
				if (player2.getInput() == -1)
					time2 -=FlxG.elapsed;
				if (player3.getInput() == -1)
					time3 -=FlxG.elapsed;
				if (player4.getInput() == -1)
					time4 -=FlxG.elapsed;
				trace(time1);
				if (_reloj < 6 && _relojTexto.visible == true)
				{
					FlxG.sound.muted = true;
					channel.stop();
					textoAzul.visible = false;
					textoRojo.visible = false;
					textoVerde.visible = false;
					textoAmarillo.visible = false;
					_relojTexto.visible = false;
				}
				if (_reloj < 1 || (player1.getInput() != -1 && player2.getInput() != -1 && player3.getInput() != -1 && player4.getInput() != -1))
				{
					FlxG.sound.muted = false;
					_pregunta.start(0);
					textoAzul.visible = false;
					textoRojo.visible = false;
					textoVerde.visible = false;
					textoAmarillo.visible = false;
					var res:Float = 50;
					res = Math.min(res,time1);
					res = Math.min(res,time2);
					res = Math.min(res,time3);
					res = Math.min(res, time4);
					if (res != time1 )
						player1.setInput(-2);
					if (res != time2)
						player2.setInput(-2);
					if (res != time3)
						player3.setInput(-2);
					if (res != time4)
						player4.setInput(-2);
					estado = "mostrando";
					if (_reloj > 1)
					{
						channel.stop();
						channel = sound.play(30000);
					}
				}
		}
	}

}